import { ShaderMaterial, Color, AdditiveBlending } from 'three'
import * as THREE from 'three'
// import fragmentShader from '../shaders/shield/frag.glsl'
// import vertexShader from '../shaders/shield/vert.glsl'
export default class EffetMaterials {
  constructor() {
    const material = new THREE.ShaderMaterial({
      uniforms: {
        iTime: {
          value: 0,
        },
        resolution: {
          value: new THREE.Vector2(1, 1),
        },
        iChannel0: {
          value: '',
        },
        iChannel1: {
          value: '',
        },
        iChannel2: {
          value: '',
        },
        iChannel3: {
          value: '',
        },
      },
      side: THREE.BackSide,
      depthWrite: true,
      transparent: false,
      vertexShader: `varying vec2 vUv;
      void main() {
        vUv = uv;
        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
      }`,
      fragmentShader: `precision highp float;
      precision highp int;
      uniform float iTime;
      varying vec2 vUv;
      const vec2 resolution = vec2(1.0, 1.0);
      vec3 palette(float t) {
        vec3 a = vec3(0.5, 0.5, 0.5);
        vec3 b = vec3(0.5, 0.5, 0.5);
        vec3 c = vec3(1.0, 1.0, 1.0);
        vec3 d = vec3(0.2, 0.4, 0.6);
        return a + b * cos(6.28318 * (c * t + d));
      }
      void main() {
        vec2 uv = vUv / resolution.xy;
        uv = (uv - 0.5) * 2.0;
        uv.x *= resolution.x / resolution.y;
        float d = length(uv);
        vec3 col = palette(d + iTime * 0.5);
        d = sin(d * 8.0 + iTime * 4.0) / 8.;
        d = abs(d);
        d = 0.01 / d;
        col *= d;
        gl_FragColor = vec4(col, 1.0);
      }`,
    })
    return material
  }
}
